package com.example.basicsactivity.activity;
import android.view.View;
import com.example.base.base.BaseActivity;
import com.example.base.utils.Utils;
import com.example.basicsactivity.app;
import com.example.basicsactivity.bean.UserData;
import com.example.basicsactivity.databinding.ActivityLoginBinding;
import org.litepal.crud.DataSupport;
public class RegisterActivity extends BaseActivity<ActivityLoginBinding> {
    @Override
    public void init() {
        viewBinding.tvRegister.setVisibility(View.GONE);
        viewBinding.tvLogin.setText("注册");
        viewBinding.tvLogin.setOnClickListener(v -> {

            String tvAccount = viewBinding.tvAccount.getText().toString();
            String tvPassword = viewBinding.tvPassword.getText().toString();

            if (Utils.get().CheckField(app.context
                    ,tvAccount
                    ,"账号不能为空！"))return;

            if (Utils.get().CheckField(app.context
                    ,tvPassword
                    ,"密码不能为空！"))return;

            UserData userData = DataSupport.where("account=?",tvAccount)
                    .findFirst(UserData.class);
            if (null!=userData){
                Utils.get().showToast(app.context,"账号已经存在！！！");
                return;
            }

            UserData bean = new UserData(getGuid(),tvAccount,tvPassword);
            if (bean.save()){
                Utils.get().showToast(app.context,"注册成功！！！");
                finish();
            }
            else{
                Utils.get().showToast(app.context,"注册失败！！！");
                return;
            }
        });
    }
}
